package org.phalanx.server.user;

import java.util.Enumeration;
import java.util.Hashtable;

import org.phalanx.server.ServerCache.CacheManager;
import org.phalanx.server.ServerCache.Cacheable;

public class UserManager {
	private CacheManager cacheMgr;
	
	public UserManager(CacheManager cacheMgr){
		this.cacheMgr = cacheMgr;
	}
	
	public PhalanxUser getUserByName(String userName){
		PhalanxUser user = null;
		
		Hashtable<Object,Cacheable> lookupTable = cacheMgr.getCache("UserCache").getInternalCacheTable();
		
		Enumeration<Cacheable> e = lookupTable.elements();
		
		boolean isFound = false;
		while (e.hasMoreElements() && !isFound){
			PhalanxUser temp = (PhalanxUser)e.nextElement();
			
			if (temp.getUserName().equals(userName)){
				user = temp;
				isFound = true;
			}
		}
		
		return user;
	}
}
